package cn.gene.timeyan.ums.webapi.ums.controller;

import cn.gene.timeyan.common.restful.JsonResult;
import cn.gene.timeyan.pojo.ums.dto.AddHonorDTO;
import cn.gene.timeyan.pojo.ums.dto.AddNewUserHonor;
import cn.gene.timeyan.pojo.ums.vo.HonorVO;
import cn.gene.timeyan.ums.service.IHonorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@Api("徽章模块")
@RequestMapping("/honor")
public class HonorController {
    @Autowired
    private IHonorService honorService;
    @GetMapping("/list")
    @ApiOperation("获取徽章列表")
    public JsonResult<List<HonorVO>> getHonorList(@RequestParam("userId") Long userId){
        System.out.println("userId"+userId);
        List<HonorVO> list=honorService.getHonorList(userId);
        System.out.println("list="+list);
        return JsonResult.ok(list);
    }
    @PostMapping("/add")
    @ApiOperation("添加新的徽章信息")
    public JsonResult<Void> addNewHonor(AddHonorDTO honorDTO){
        honorService.addNewHonor(honorDTO);
        return JsonResult.ok();
    }
    @PostMapping("/addInfo")
    @ApiOperation("添加用户获取徽章信息")
    public JsonResult<Void> addInfo(AddNewUserHonor addNewUserHonor){
        honorService.addNewUserHonor(addNewUserHonor);
        return JsonResult.ok();
    }
    @PostMapping("/update/name")
    @ApiOperation("修改徽章名称")
    public JsonResult<Void> updateHonorName(@RequestParam("name") String name,@RequestParam("id")Long honorId){
        honorService.updateHonorName(name,honorId);
        return JsonResult.ok();
    }
    @PostMapping("/update/way")
    @ApiOperation("修改徽章获取方式")
    public JsonResult<Void> updateHonorAcquireWay(@RequestParam("way") String way,@RequestParam("id")Long honorId){
        honorService.updateHonorAcquireWay(way,honorId);
        return JsonResult.ok();
    }
    @PostMapping("/update/available")
    @ApiOperation("修改徽章可获取")
    public JsonResult<Void> updateHonorAvailable(@RequestParam("available") Character available,@RequestParam("id")Long honorId){
        honorService.updateHonorAvailable(available,honorId);
        return JsonResult.ok();
    }
    @PostMapping("/update/endTime")
    @ApiOperation("修改徽章获取截止时间")
    public JsonResult<Void> updateHonorEndTime(@RequestParam("end")LocalDateTime end, @RequestParam("id")Long honorId){
        honorService.updateHonorEndTime(end,honorId);
        return JsonResult.ok();
    }
    @PostMapping("/update/img")
    @ApiOperation("修改徽章图像")
    public JsonResult<Void> updateHonorImg(@RequestParam("file") MultipartFile imgFile,@RequestParam("id")Long honorId){
        honorService.updateHonorImg(imgFile,honorId);
        return JsonResult.ok();
    }
}
